<?php


namespace app\common\service\user;


use app\admin\model\user\Bill;
use app\admin\model\user\User;
use app\admin\model\user\UserBill;
use app\api\validate\BillCheck;
use app\common\service\BaseService;

class BillService extends BaseService
{
    /**
     * 创建流水表
     * Author:YangXinPeng
     * @param $params
     */
    public static function createBill($order,$pm,$type,$title)
    {
        $params=[];
        $params['uid'] = $order['user_id'];
        $params['order_id'] = $order['order_no'];
        $params['category'] = "now_money";
        $params['type']  = $type;
        $number = $order['pay_price'];
        $params['number'] = $number;
        $params['status'] = 1;
        $params['pm'] = $pm;
        $params['title'] = $title;
        try {
            validate(BillCheck::class)->check($params);
        }catch (\Exception $e){
            return self::fail('参数错误');
        }
        Bill::create($params);
    }

    public static function billList($page, $limit, $where)
    {
        $count = UserBill::where($where)
            ->count();
        $list = UserBill::where($where)
            ->with('userBill')
            ->page($page, $limit)
            ->order('id','desc')
            ->select();
//        dd($list);
        $data = [
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list,
        ];
        return $data;
    }
}